package com.cn.learn.creator.controller;

import com.cn.learn.creator.domain.entity.Column;
import com.cn.learn.creator.domain.entity.DataBase;
import com.cn.learn.creator.domain.entity.Table;
import com.cn.learn.creator.domain.vo.ResultVO;
import com.cn.learn.creator.service.IDataBaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName DataBaseController
 * @Description 数据库相关的控制器
 * @Author JiJiang
 * @Date 2023/7/8 13:38
 * @Version 1.0
 */

@RestController
@RequestMapping("/database")
public class DataBaseController {


    @Resource
    private IDataBaseService dataBaseService;


    /**
     * 根据条件查询字段列表
     *
     * @param conditions
     * @return
     */
    @GetMapping("/list/column")
    public ResultVO<List<Column>> getColumnsByConditions(@ModelAttribute Column conditions) {

        return dataBaseService.searchColumnsByConditions(conditions);

    }


    /**
     * 根据条件获取所有的表
     *
     * @param conditions
     * @return
     */
    @GetMapping("/list/table")
    public ResultVO<List<Table>> getTablesByConditions(@ModelAttribute Table conditions) {
        return dataBaseService.searchTablesByConditions(conditions);
    }


    /**
     * 获取本地MySQL数据库的库
     *
     * @return
     */
    @GetMapping("/list")
    public ResultVO<List<DataBase>> getDataBasesByConditions(@ModelAttribute DataBase conditions) {

        return dataBaseService.searchDataBasesByConditions(conditions);
    }


}
